<template>
  <div class="app-container">
    <div class="search-container">
      <el-form :model="searchParam" :inline="true" label-width="94px">
        <!-- <el-form-item label="工序">
          <el-select
            v-model="searchParam.processId"
            placeholder="请选择工序"
            clearable
            filterable
            @change="processChange"
          >
            <el-option
              v-for="item in processList"
              :key="item.id"
              :label="item.processCode"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="生产线">
          <el-select
            v-model="searchParam.equipId"
            placeholder="请选择生产设备"
            clearable
            filterable
            @change="equipChange"
          >
            <el-option
              v-for="item in equipList"
              :key="item.id"
              :label="item.equipCode"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="项目">
          <el-select
            v-model="searchParam.projectId"
            placeholder="请选择项目"
            clearable
            filterable
            @change="projectChange"
          >
            <el-option
              v-for="item in projectList"
              :key="item.id"
              :label="item.projectCode"
              :value="item.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="产品型号">
          <el-select
            v-model="searchParam.productId"
            placeholder="请选择产品型号"
            clearable
            filterable
            @change="productChange"
          >
            <el-option
              v-for="item in productList"
              :key="item.id"
              :label="item.productCode"
              :value="item.id"
            />
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item label="检具类型">
            <el-select
              v-model="searchParam.gageEquipToolKind"
              placeholder="请选择量检具类型"
              clearable
              @change="toolKindChange"
            >
              <el-option
                v-for="item in useDictionary('InspectionToolKind')"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item> -->

        <SearchFormGroup
          :data="searchParam"
          @change-search="handleSearchChange"
          @change-gageEquipCode="changeEquipCode"
        />
        <!-- <el-form-item label="检具名称">
          <el-select
            v-model="searchParam.gageEquipMarkCode"
            placeholder="请选择检具名称"
            clearable
            filterable
          >
            <el-option
              v-for="item in gageEquipList"
              :key="item.toolCode"
              :label="item.toolName"
              :value="item.toolCode"
            />
          </el-select>
        </el-form-item> -->
        <el-form-item label="特性名称">
          <el-select
            v-model="searchParam.paramId"
            placeholder="请选择特性名称"
            clearable
            filterable
            :filter-method="customFilter5"
            :disabled="!canSelectSpecific"
            @change="search"
          >
            <el-option
              v-for="item in filteredOptions5"
              :key="item.id"
              :label="item.paramName"
              :value="item.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="search">
            <i-ep-search />
            搜索
          </el-button>
          <el-button @click="resetBtn">
            <i-ep-refresh />
            重置
          </el-button>
          <!-- <el-button type="primary" link @click="collapsed = !collapsed">
            {{ collapsed ? "展开" : "收起" }}
            <i-ep-arrowUp v-if="!collapsed" class="ml-[3px]" />
            <i-ep-arrowDown v-else class="ml-[3px]" />
          </el-button> -->
        </el-form-item>
      </el-form>
    </div>

    <el-card shadow="never" class="table-container">
      <template #header>
        <el-button type="success" plain @click="synchronous()">
          <i-ep-plus />
          同步
        </el-button>
        <!-- <el-button
          type="danger"
          plain
          :disabled="ids.length === 0"
          @click="handleTableDelete()"
        >
          <i-ep-delete />
          删除
        </el-button> -->
      </template>

      <el-table
        ref="dataTableRef"
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        :maxHeight="tableHeight"
        @selection-change="handleSelectionChange"
      >
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column
          label="工段"
          prop="workshopSectionCode"
          min-width="80"
          align="center"
          show-overflow-tooltip
        />
        <el-table-column
          label="工序"
          prop="processCode"
          min-width="80"
          align="center"
          show-overflow-tooltip
        />
        <el-table-column
          label="生产线"
          prop="equipCode"
          min-width="100"
          align="center"
          show-overflow-tooltip
        />
        <el-table-column
          label="型号描述"
          prop="modelName"
          min-width="100"
          align="center"
          show-overflow-tooltip
        />

        <!-- <el-table-column
          label="项目描述"
          prop="projectName"
          min-width="100"
          align="center"
          show-overflow-tooltip
        /> -->
        <el-table-column
          label="产品型号"
          prop="modelCode"
          min-width="100"
          align="center"
          show-overflow-tooltip
        />
        <el-table-column
          label="检具类别"
          prop="groupCode"
          min-width="100"
          align="center"
          show-overflow-tooltip
        />
        <el-table-column
          label="特性"
          prop="paramName"
          min-width="100"
          align="left"
          show-overflow-tooltip
        />
        <!-- <el-table-column
          label="特性项名称"
          prop="paramName"
          min-width="100"
          show-overflow-tooltip
        >
        </el-table-column> -->
        <el-table-column
          label="公称尺寸"
          prop="parameterStandards"
          min-width="85"
          show-overflow-tooltip
          align="right"
        />
        <el-table-column
          label="公差下限"
          prop="lowerLimitValue"
          min-width="85"
          show-overflow-tooltip
          align="right"
        />
        <el-table-column
          label="公差上限"
          prop="upperLimitValue"
          min-width="85"
          show-overflow-tooltip
          align="right"
        />
        <!--        <el-table-column-->
        <!--          label="公差下限类型"-->
        <!--          prop="lowerLimitType"-->
        <!--          min-width="110"-->
        <!--          show-overflow-tooltip-->
        <!--          align="center"-->
        <!--        />-->
        <!--        <el-table-column-->
        <!--          label="公差上限类型"-->
        <!--          prop="upperLimitType"-->
        <!--          min-width="110"-->
        <!--          show-overflow-tooltip-->
        <!--          align="center"-->
        <!--        />-->
        <el-table-column
          label="预警工单"
          min-width="78"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            <el-tag v-if="handleCheckAllChange1(scope.row)" type="success">
              是
            </el-tag>
            <el-tag v-else type="info"> 否</el-tag>
          </template>
        </el-table-column>

        <el-table-column
          label="预警邮件"
          min-width="78"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            <el-tag v-if="handleCheckAllChange2(scope.row)" type="success">
              是
            </el-tag>
            <el-tag v-else type="info"> 否</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="特性状态"
          min-width="78"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            {{ "" }}
          </template>
        </el-table-column>
        <el-table-column
          label="责任人"
          min-width="78"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            {{ scope.row.responsibleUserName }}
          </template>
        </el-table-column>
        <!-- <el-table-column
          label="单值图预警工单"
          prop="isSingleOrder"
          min-width="180"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            <el-tag v-show="scope.row.isSingleOrder == 1" type="success">
              是
            </el-tag>
            <el-tag v-show="!scope.row.isSingleOrder" type="info"> 否</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="均值图预警工单"
          prop="isAverageOrder"
          min-width="180"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            <el-tag v-show="scope.row.isAverageOrder == 1" type="success">
              是
            </el-tag>
            <el-tag v-show="!scope.row.isAverageOrder" type="info"> 否</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="长期综合过程能力趋势图预警工单"
          prop="isLongOrder"
          min-width="240"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            <el-tag v-show="scope.row.isLongOrder == 1" type="success">
              是
            </el-tag>
            <el-tag v-show="!scope.row.isLongOrder" type="info"> 否</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="阶段综合过程能力趋势图预警工单"
          prop="isStageOrder"
          min-width="240"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            <el-tag v-show="scope.row.isStageOrder == 1" type="success">
              是
            </el-tag>
            <el-tag v-show="!scope.row.isStageOrder" type="info"> 否</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="多份特定送检状态过程分析趋势图预警工单"
          prop="isFeaturesOrder"
          min-width="300"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            <el-tag v-show="scope.row.isFeaturesOrder == 1" type="success">
              是
            </el-tag>
            <el-tag v-show="!scope.row.isFeaturesOrder" type="info"> 否</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="单值图预警"
          prop="isSingle"
          min-width="110"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            <el-tag v-show="scope.row.isSingle == 1" type="success">
              是
            </el-tag>
            <el-tag v-show="!scope.row.isSingle" type="info"> 否</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="均值图预警"
          prop="isAverage"
          min-width="110"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            <el-tag v-show="scope.row.isAverage == 1" type="success">
              是
            </el-tag>
            <el-tag v-show="!scope.row.isAverage" type="info"> 否</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="长期综合过程能力趋势图预警"
          prop="isLong"
          min-width="240"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            <el-tag v-show="scope.row.isLong == 1" type="success"> 是 </el-tag>
            <el-tag v-show="!scope.row.isLong" type="info"> 否</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="阶段综合过程能力趋势图预警"
          prop="isStage"
          min-width="240"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            <el-tag v-show="scope.row.isStage == 1" type="success"> 是 </el-tag>
            <el-tag v-show="!scope.row.isStage" type="info"> 否</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="多份特定送检状态过程分析趋势图预警"
          prop="isFeatures"
          min-width="300"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            <el-tag v-show="scope.row.isFeatures == 1" type="success">
              是
            </el-tag>
            <el-tag v-show="!scope.row.isFeatures" type="info"> 否</el-tag>
          </template>
        </el-table-column> -->
        <!-- <el-table-column
          label="工序名称"
          prop="processName"
          min-width="100"
          show-overflow-tooltip
        >
        </el-table-column> -->

        <!-- <el-table-column
          label="设备名称"
          prop="equipName"
          min-width="100"
          show-overflow-tooltip
        >
        </el-table-column> -->

        <!-- <el-table-column
          label="项目名称"
          prop="projectName"
          min-width="100"
          show-overflow-tooltip
        >
        </el-table-column> -->

        <!-- <el-table-column
          label="产品型号名称"
          prop="modelName"
          min-width="100"
          show-overflow-tooltip
        >
        </el-table-column> -->

        <!-- <el-table-column
          label="检具设备号名称"
          prop="gageEquipMarkName"
          min-width="100"
          show-overflow-tooltip
        >
        </el-table-column> -->
        <!-- 
        <el-table-column fixed="right" label="操作" width="110" align="center">
          <template #default="scope">
            <el-tooltip
              :hide-after="0"
              effect="light"
              content="查看"
              placement="top"
            >
              <el-button
                type="primary"
                size="small"
                link
                @click="openDialogdetail(scope.row)"
              >
                <i-ep-search />
              </el-button>
            </el-tooltip>

            <el-tooltip
              :hide-after="0"
              effect="light"
              content="编辑"
              placement="top"
            >
              <el-button
                type="primary"
                size="small"
                link
                @click="openDialog(scope.row)"
              >
                <i-ep-edit />
              </el-button>
            </el-tooltip> -->
        <!-- <el-tooltip
              :hide-after="0"
              effect="light"
              content="删除"
              placement="top"
            >
              <el-button
                type="primary"
                size="small"
                link
                @click="deleteItem(scope.row.id)"
              >
                <i-ep-delete />
              </el-button>
            </el-tooltip> 
          </template>
        </el-table-column>
        -->
        <el-table-column label="操作" width="200" align="center">
          <template #default="scope">
            <el-button
              type="primary"
              size="small"
              link
              @click="openDialogdetail(scope.row)"
              ><i-ep-search />
              查看
            </el-button>
            <el-button
              type="primary"
              size="small"
              link
              @click="openDialog(scope.row)"
              ><i-ep-edit />
              编辑
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        :background="true"
        :current-page="pageable.pageNum"
        :page-size="pageable.pageSize"
        :page-sizes="[10, 25, 50, 100]"
        :total="pageable.total"
        layout="total, sizes, prev, pager, next, jumper"
        class="mt-[20px]"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>

    <pcmmeasurefeatures-edit
      :visible="addDialog.visible"
      :title="addDialog.title"
      :data="addDialog.data"
      @reset-table="(id:string) => (id?.length ? getTableList() : getTableList())"
      :is-readonly="addDialog.readvisible"
      @change-visible="changeVisible"
    />

    <pcmConfigMeasurementsEdit
      :visible="configMeasurementDialog.visible"
      :title="configMeasurementDialog.title"
      :data="configMeasurementDialog.data"
      :abilityType="configMeasurementDialog.abilityType"
      @reset-table="(id:string) => (id?.length ? getTableList() : getTableList())"
      :is-readonly="configMeasurementDialog.readvisible"
      @change-visible="changeConfigMeasurementDialogVisible"
    />
  </div>
</template>

<script setup lang="ts">
import {
  useDictionary,
  useTable,
  useComputeTableHeight,
} from "@/utils/useTable";
import request from "@/utils/request";
import SearchFormGroup from "@/views/pcm/pcmMonitoring/components/SearchFormGroup1.vue";
import {
  getMdminspectiontoolApi,
  getMdmProcessEquipApi,
  getMdmProcessProjectApi,
  getMdmproductinfosApi,
  getMdmprojectinfosApi,
  getSpecificListApi,
  getMdmprocessListApi,
  getMdmProcessEquipApi1,
  getMdminspectionGroupApi,
} from "@/utils/commonData";
import pcmConfigMeasurementsEdit from "@/views/pcm/pcmconfigmeasurements/components/pcmconfigmeasurements-edit.vue";
import { deepClone } from "@/utils/commonHooks";
import _ from "lodash-es";

defineOptions({
  name: "PCMPCMMEASUREFEATURES",
  inheritAttrs: false,
});

// 请求参数
const requestApi = "/dmpDosPcm/pcmmeasurefeaturesgroup/queryByPage";

// 是否需要分页
const pagination = true;

const initParam = {};

// 初始化搜索参数数据
const searchParamInit = {
  // 工段
  workshopSectionId: "",
  workshopSectionCode: "",
  // 项目
  // projectCode: "",
  // projectId: "",
  // 工序
  processCode: "",
  processId: "",
  // 设备
  equipCode: "",
  equipId: "",
  // 产品型号
  productCode: "",
  productId: "",
  // 检具类型
  gageEquipToolKind: "",
  // 检具名称
  gageEquipCode: "",
  // 机器号
  gageEquipMarkCode: "",
  // 特性
  paramId: "",
  toolGroupId: "",
};

const deleteParam = {
  api: "/dmpDosPcm/pcmmeasurefeaturesgroup/delete",
  data: {},
};

// 数据请求错误后处理
function requestError() {}

const tableHeight = ref();

function dataCallBack(data: any) {
  setTimeout(() => {
    tableHeight.value = useComputeTableHeight();
  }, 100);
  return data;
}

// 表格操作 Hooks
const {
  tableData,
  pageable,
  searchParam,
  ids,
  getTableList,
  search,
  reset,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange,
  handleTableDelete,
  loading,
}: any = useTable(
  requestApi,
  initParam,
  searchParamInit,
  pagination,
  dataCallBack,
  requestError,
  deleteParam
);

// --------------------------------------------------------------------------------------------------------组件 开始
// 处理传回数据
const handleSearchChange = (data) => {
  Object.assign(searchParam.value, data);
  if (searchParam.value.gageEquipCode) {
    searchParam.value.toolGroupId = oldGageEquipList1.value.filter(
      (item) => item.groupCode == searchParam.value.gageEquipCode
    )[0].id;
  } else {
    searchParam.value.toolGroupId = "";
  }

  // 可执行字段相关的特定逻辑
};

// 间距变化
const changeEquipCode = (id: string) => {
  if (id) {
    searchParam.paramId = "";
  }
};
// --------------------------------------------------------------------------------------------------------组件 结束
const resetBtn = () => {
  reset();
};

onMounted(() => {
  getTableList();
});

const addDialog = reactive<DialogOption>({
  visible: false,
  readvisible: false,
  title: "",
  data: {},
});

const configMeasurementDialog = reactive<
  DialogOption & { abilityType: string }
>({
  visible: false,
  readvisible: false,
  title: "",
  data: {},
  abilityType: "",
});

// 查询详情
async function getInfo(id: string) {
  request({
    url: `/dmpDosPcm/pcmmeasurefeaturesgroup/get/${id}`,
    method: "get",
  })
    .then((data) => {
      data.data.isRatioUp = data.data.isRatioUp == 1;
      data.data.isRatioDow = data.data.isRatioDow == 1;
      data.data.isSingle = data.data.isSingle == 1;
      data.data.isAverage = data.data.isAverage == 1;
      data.data.isLong = data.data.isLong == 1;
      data.data.isStage = data.data.isStage == 1;
      data.data.isFeatures = data.data.isFeatures == 1;
      data.data.isSingleOrder = data.data.isSingleOrder == 1;
      data.data.isAverageOrder = data.data.isAverageOrder == 1;
      data.data.isLongOrder = data.data.isLongOrder == 1;
      data.data.isStageOrder = data.data.isStageOrder == 1;
      data.data.isFeaturesOrder = data.data.isFeaturesOrder == 1;
      addDialog.data = data.data;
      addDialog.visible = true;
    })
    .catch((res) => {
      console.log(res);
    });
}

/** 打开测量特性定义表单弹窗 */
function openDialog(roleObj?: Object) {
  if (roleObj) {
    addDialog.title = "产品特性配置清单-修改";
    getInfo(roleObj.id);
  } else {
    addDialog.title = "特性项-新增";
    addDialog.visible = true;
  }
  addDialog.readvisible = false;
}

async function synchronous() {
  const { data } = await request({
    url: `/dmpDosPcm/pcmmeasurefeatures/synchronousProgram`,
    method: "post",
    data: {},
  });
  ElMessage.success("同步成功！");
  search();
}

/** 打开测量特性定义表单弹窗 详情 */
function openDialogdetail(roleObj?: any) {
  addDialog.title = "产品特性配置清单-详情";
  getInfo(roleObj.id);
  addDialog.readvisible = true;
}

function changeVisible(value: boolean) {
  addDialog.visible = value;
  if (!value) {
    addDialog.data = {};
  }
}

function changeConfigMeasurementDialogVisible(value: boolean) {
  configMeasurementDialog.visible = value;
  if (!value) {
    configMeasurementDialog.data = {};
  }
}

// 搜索项折叠
const collapsed = ref(false);

async function deleteItem(id: any) {
  ElMessageBox.confirm("确认删除已选中的数据项?", "警告", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(async () => {
    const { data } = await request({
      url: `/dmpDosPcm/pcmmeasurefeaturesgroup/deleteItem/${id}`,
      method: "post",
    });
    search();
  });
}

onMounted(() => {
  // 获取table列表
  getTableList();
  // -----------------------
  // 获取项目列表
  getProjectList({});

  // 获取工序列表
  getProcessList({});

  // 获取设备列表
  getEquipList({});

  // 获取产品型号列表
  getProductList({});

  // // 获取量检具列表
  getGageEquipList({});
  // 检具分组
  getGageEquipList1("");
});

const oldGageEquipList1 = ref<any>([]);
async function getGageEquipList1(type: string) {
  oldGageEquipList1.value = (await getMdminspectionGroupApi({})) || [];
}

// 通过工序查询设备列表
const equipList = ref(<any>[]);

async function getEquipList(params: Object) {
  equipList.value = (await getMdmProcessEquipApi1(params)) || [];
}

function equipChange(id: string) {
  searchParam.value.processId = "";
  searchParam.value.processCode = "";
  searchParam.value.processName = "";
  searchParam.value.productId = "";
  searchParam.value.productCode = "";
  searchParam.value.processId = "";
  searchParam.value.processCode = "";
  searchParam.value.processName = "";
  if (id) {
    const current: any =
      equipList.value?.filter((e: any) => e.id === id)[0] ?? {};
    searchParam.value.equipCode = current.equipCode || "";

    getProcessList({ equipId: id });
    getProductList({ equipId: id });
    getProjectList({ equipId: id });
  } else {
    searchParam.value.equipCode = "";
  }
}

// 获取工序列表
const processList = ref<any>([]);

async function getProcessList(params: Object) {
  processList.value = (await getMdmprocessListApi(params)) || [];
}

function processChange(id: string) {
  searchParam.value.equipId = "";
  searchParam.value.equipCode = "";
  searchParam.value.productId = "";
  searchParam.value.productCode = "";
  searchParam.value.projectId = "";
  searchParam.value.projectCode = "";
  searchParam.value.projectName = "";

  if (id) {
    const current: any =
      processList.value?.filter((e: any) => e.id === id)[0] ?? {};
    searchParam.value.processCode = current.processCode || "";
    getEquipList({ processId: id });
    getProductList({ processId: id });
    getProjectList({ processId: id });
  } else {
    searchParam.value.processCode = "";
    equipList.value = [];
  }
}

// 获取项目列表
const projectList = ref<any>([]);

async function getProjectList(params: Object) {
  projectList.value = (await getMdmprojectinfosApi(params)) || [];
}

function projectChange(id: string) {
  searchParam.value.equipId = "";
  searchParam.value.equipCode = "";
  searchParam.value.processId = "";
  searchParam.value.processCode = "";
  searchParam.value.processName = "";
  searchParam.value.productId = "";
  searchParam.value.productCode = "";
  if (id) {
    const current: any =
      projectList.value?.filter((e: any) => e.id === id)[0] ?? {};
    searchParam.value.projectCode = current.projectCode || "";
    getEquipList({ projectId: id });
    getProductList({ projectId: id });
    getProcessList({ projectId: id });
  } else {
    searchParam.value.projectCode = "";
    // equipList.value = [];
    // processList.value = [];
    // productList.value = [];
  }
}

// 获取产品型号列表
const productList = ref<any>([]);

async function getProductList(params) {
  productList.value = (await getMdmproductinfosApi(params)) || [];
}

function productChange(id: string) {
  searchParam.value.equipId = "";
  searchParam.value.equipCode = "";
  searchParam.value.projectId = "";
  searchParam.value.projectName = "";
  searchParam.value.projectCode = "";
  searchParam.value.processId = "";
  searchParam.value.processCode = "";
  searchParam.value.processName = "";
  if (id) {
    const current: any =
      productList.value?.filter((e: any) => e.id === id)[0] ?? {};
    searchParam.value.productCode = current.productCode || "";
    getEquipList({ productId: id });
    getProcessList({ productId: id });
    getProjectList({ productId: id });
  } else {
    searchParam.value.productCode = "";
  }
}

// 量检具类型变化
function toolKindChange(type: string) {
  searchParam.value.gageEquipCode = "";
  searchParam.value.gageEquipMarkCode = "";
  if (type) {
    getGageEquipList(type);
  } else {
    gageEquipList.value = [];
  }
}

// 获取量检具列表
const gageEquipList = ref<any>([]);

async function getGageEquipList(params) {
  gageEquipList.value = (await getMdminspectiontoolApi({})) || [];
}

// 获取特性值列表
const specificList = ref<any>([]);

async function getSpecificList() {
  specificList.value =
    (await getSpecificListApi({
      equipId: searchParam.value.equipId,
      toolGroupId: searchParam.value.toolGroupId,
      modelId: searchParam.value.productId,
      processId: searchParam.value.processId,
    })) || [];
  filteredOptions5.value = deepClone(specificList.value);
}
const filteredOptions5 = ref([]);
// 使用 debounce 包装过滤方法
const customFilter5 = _.debounce((query) => {
  if (!query) {
    filteredOptions5.value = [...specificList.value];
    return;
  }
  filteredOptions5.value = specificList.value.filter((option: any) =>
    option.paramName.toLowerCase().includes(query.toLowerCase())
  );
}, 300);

// 检测必填项，筛选特性值列表
const canSelectSpecific = ref(false);
watch(
  () => searchParam.value,
  (newVal) => {
    if (
      newVal.equipCode &&
      newVal.gageEquipCode &&
      newVal.productCode &&
      newVal.processCode
    ) {
      canSelectSpecific.value = true;
      getSpecificList();
    } else {
      searchParam.value.paramId = "";
      canSelectSpecific.value = false;
      specificList.value = [];
      filteredOptions5.value = [];
    }
    searchParam.value.gageEquipMarkCode = newVal.gageEquipCode;
  },
  {
    deep: true,
  }
);

const getConfigMeasurement = async (programId, abilityType) => {
  await request({
    url: `/dmpDosPcm/pcmconfigmeasurements/getByProgram`,
    method: "get",
    params: { programId, abilityType },
  })
    .then(({ data }) => {
      configMeasurementDialog.data = data ?? { programId, abilityType };
    })
    .catch((res) => {
      console.log(res);
    });
};

const configMeasurement = async (row, abilityType) => {
  configMeasurementDialog.title = "测量特性定义详情";
  configMeasurementDialog.visible = true;
  await getConfigMeasurement(row.id, abilityType);
  configMeasurementDialog.readvisible = false;
  configMeasurementDialog.abilityType = abilityType;
};

// 预警工单 回显
function handleCheckAllChange1(formData: any) {
  if (
    formData.isSingleOrder == 0 &&
    formData.isAverageOrder == 0 &&
    formData.isLongOrder == 0 &&
    formData.isStageOrder == 0 &&
    formData.isFeaturesOrder == 0
  ) {
    return false;
  } else {
    return true;
  }
}

// 预警邮件 回显
function handleCheckAllChange2(formData: any) {
  if (
    formData.isSingle == 0 &&
    formData.isAverage == 0 &&
    formData.isLong == 0 &&
    formData.isStage == 0 &&
    formData.isFeatures == 0
  ) {
    return false;
  } else {
    return true;
  }
}
</script>
